<?php

namespace App\Http\Resources;

use App\Models\Configuration;
use Carbon\Carbon;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Env;

class UserResource extends JsonResource
{
    public function toArray($request)
    {
        $this->resource->makeHidden([
            'remark','created_at','updated_at','agent_id','parent_id','lang','timezone','shoptype','identity','ip_register','ip_last','login_time_last'
        ])->toArray();

        $data = parent::toArray($request);
        if(empty($data['avatar'])){
            $data['avatar'] = request()->header('Avatar','');
        }else{
            $data['avatar'] = strpos($data['avatar'],'https') === false ? sprintf('%s/%s', aliyun_domain(), $data['avatar']) : $data['avatar'];
        }

        $data['payment_password'] = isset($data['payment_password']) && $data['payment_password'];
        $data['currency_symbol'] = Configuration::getItem('currency_symbol');

        /*

        //体验VIP功能
        $data['experience_vip'] = 1;
        if (isset($data['experience_vip_times']) && $data['experience_vip_times']>0) {
            $data['experience_vip'] = 0;
        }else{
            if (isset($data['vip']['value']) && $data['vip']['value'] != 0){
                $data['experience_vip'] = 0;
            }
        }

        unset($data['experience_vip_times']);

        if(empty($data['card'])){
            $data['card']['id'] = 0;
            $data['card']['number'] = '';
        }
        */
        return $data;
    }
}
